package cn.wolfcode.p2p.business.service.impl;
import cn.wolfcode.p2p.business.domain.SystemAccount;
import cn.wolfcode.p2p.business.domain.SystemAccountFlow;
import cn.wolfcode.p2p.business.mapper.SystemAccountFlowMapper;
import cn.wolfcode.p2p.business.service.ISystemAccountFlowService;
import cn.wolfcode.p2p.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

@Service
public class SystemAccountFlowImpl implements ISystemAccountFlowService {
    @Autowired
    private SystemAccountFlowMapper systemAccountFlowMapper;


    public void createBaseFlow(SystemAccount systemAccount,BigDecimal amount,String note,Integer actionType){
        SystemAccountFlow systemAccountFlow = new SystemAccountFlow();
        systemAccountFlow.setActionTime(new Date());
        systemAccountFlow.setActionType(actionType);
        systemAccountFlow.setAmount(amount);
        systemAccountFlow.setNote(note);
        systemAccountFlow.setUsableAmount(systemAccount.getUsableAmount());
        systemAccountFlow.setFreezedAmount(systemAccount.getFreezedAmount());
        systemAccountFlowMapper.insert(systemAccountFlow);
    }

    @Override
    public void createReceiveManageChargeFlow(SystemAccount systemAccount, BigDecimal amount, String bidRequestTitle) {
        String note = "["+bidRequestTitle+"]标的借款人受到借款,支付平台管理费["+amount+"]";
        createBaseFlow(systemAccount,amount,note,Constant.SYSTEM_ACCOUNT_ACTIONTYPE_MANAGE_CHARGE);

    }

    @Override
    public void createReceiveInterestManagerChargeFlow(SystemAccount systemAccount,BigDecimal amount,String bidRequestTitle,int monthIndex) {
        String note = "[" + bidRequestTitle + "]标投资人收到["+monthIndex+"]期利息,平台收取利息管理费["+amount+"]元";
        createBaseFlow(systemAccount,amount,note, Constant.SYSTEM_ACCOUNT_ACTIONTYPE_INTREST_MANAGE_CHARGE);
    }

    @Override
    public void createPaymentExperienceInterest(SystemAccount systemAccount, BigDecimal amount, String bidRequestTitle) {
        String note = "支付[" + bidRequestTitle + "]体验标利息,平台可用余额减少["+amount+"]元";
        createBaseFlow(systemAccount,amount,note, Constant.SYSTEM_ACCOUNT_PAYMENT_EXPERIENCE_INTEREST);
    }

    @Override
    public void createReceiveExperienceInterestManagerChargeFlow(SystemAccount systemAccount,BigDecimal amount,String bidRequestTitle) {
        String note = "[" + bidRequestTitle + "]标投资人收到体验金利息,平台收取利息管理费["+amount+"]元";
        createBaseFlow(systemAccount,amount,note, Constant.SYSTEM_ACCOUNT_ACTIONTYPE_INTREST_MANAGE_CHARGE);
    }

}
